package cate.common.table.farm.island.row;

import cate.common.table.ERow;
import cate.common.table.XSSFRowWrap;
import cate.common.table.item.hero.row.HeroBaseRow;
import cp.solution.util.str.Str;
import easy.java.dev.note.NoteClass;
import easy.java.dev.note.NoteField;
import org.apache.commons.lang3.StringUtils;

import java.util.ArrayList;
import java.util.List;

@NoteClass(value = "迷失神庙增益")
public class IslandGainRow extends ERow {
    @NoteField(value = "技能ID")
    public int skillId;

    @NoteField(value = "原型ID")
    public int protoId;

    @NoteField("属性")
    public String attrStr;

    @NoteField(value = "种族")
    private String campStr;

    @NoteField(value = "职业")
    private String jobStr;

    @NoteField(value = "层数")
    private String floorStr;

    @Override
    public void parse(XSSFRowWrap xrw) {
        super.parse(xrw);
        this.id = xrw.getInteger("增益ID", 0);
        this.skillId = xrw.getInteger("技能ID", 0);
        this.protoId = xrw.getInteger("原型ID", 0);
        this.attrStr = xrw.getString("属性");
        this.campStr = xrw.getString("种族");
        this.jobStr = xrw.getString("职业");
        this.floorStr = xrw.getString("层数");
    }

    public List<Integer> camps = new ArrayList<>();
    public List<Integer> jobs = new ArrayList<>();
    public List<Integer> heros = new ArrayList<>();
    public List<Integer> floors = new ArrayList<>();

    @Override
    public void decode() {
        if (StringUtils.isNotBlank(campStr)) {
            camps = Str.strArr2intList(campStr.split("#"));
        }
        if (StringUtils.isNotBlank(jobStr)) {
            jobs = Str.strArr2intList(jobStr.split("#"));
        }
        if (StringUtils.isNotBlank(floorStr)) {
            floors = Str.strArr2intList(floorStr.split("#"));
        }
    }

    public boolean match(HeroBaseRow heroBaseRow, int floor) {
        if (!matchList(camps, heroBaseRow.camp)) {
            return false;
        }
        if (!matchList(jobs, heroBaseRow.job)) {
            return false;
        }
        if (!matchList(heros, heroBaseRow.protoId)) {
            return false;
        }
        return matchList(floors, floor);
    }

    private boolean matchList(List<Integer> list, int num) {
        if (list == null || list.isEmpty()) {
            return true;
        }
        return list.contains(num);
    }
}
